<template>
  <div class="scoreStatistics scrollY">
    <Title label="评分总览" />
    <div class="overview">
      <ul class="dataSetNumber">
        <li>
          <img src="@/assets/score11.png" alt="" />
          <div class="score">
            <span class="label">数据集总数量</span>
            <span class="value">31</span>
          </div>
        </li>
        <li>
          <img src="@/assets/score22.png" alt="" />
          <div class="score">
            <span class="label">平均评分</span>
            <span class="value">80.5</span>
          </div>
        </li>
      </ul>
      <div style="flex: 4">
        <basicRadar />
      </div>
      <ul class="yAxisDataUl" style="flex: 1">
        <li v-for="(item, index) in datas.yAxisData">
          <span>{{ item.label }}</span>
          <span class="yColor" :style="{ background: item.itemStyle.color }"></span>
        </li>
      </ul>
      <div style="flex: 5">
        <bar :datas="datas" :title="title" />
      </div>
    </div>
    <div class="scoreAndUpload">
      <ul class="scoreUl">
        <li @click="handleScoreItem(index)" :class="{active:activeIndex === index}" v-for="(item, index) in scoreUl" :key="index">{{ item.label }}</li>
      </ul>
      <span class="uploadData" @click="handleUploadData">上传数据集</span>
    </div>
    <ul class="scoreList">
      <li @click="handleScoreListitem(item)" class="scoreListItem" v-for="(item, index) in datasets" :key="index">
        <div class="label">{{ item.name }}</div>
        <p class="value">
          {{ item.description }}
        </p>
        <div class="lookList">
          <span><el-icon class="elIcon">
              <Download />
            </el-icon>23</span>
          <span><el-icon class="elIcon">
              <View />
            </el-icon>23</span>
          <span><el-icon class="elIcon">
              <Clock />
            </el-icon>{{ item.createTime }}</span>
        </div>
      </li>
    </ul>
    <div class="pagination">
      <el-pagination
       v-model:current-page="pageNum"
       :page-size="pageSize" :pager-count="11" layout="prev, pager, next" :total="total" 
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
    </div>
    <!-- 上传数据集 -->
    <dialogUploadDataSet v-model:isVisible="isVisible" :childFn="getDatasetsList" />
  </div>
</template>

<script setup lang="ts">
import Title from "@/components/Title.vue";
import bar from "@/components/echart/bar.vue";
import dialogUploadDataSet from "./Dialog/dialogUploadDataSet.vue";
import basicRadar from "@/components/echart/basicRadar.vue";
import { ref, reactive } from "vue";
import {
  Delete,
  Plus,
  Edit,
  Search,
  Share,
  Upload,
  Refresh,
} from "@element-plus/icons-vue";
import { useRouter } from 'vue-router';
import { datasetsList } from '@/api/home';
import moment from 'moment';
import bus from 'vue3-eventbus'

const activeIndex = ref(0);
const activeName = ref("project");
const title = "各行政区碳排放量情况";
const datas = {
  // 各行政区碳排放量情况
  xAxisData: ["90-100分", "80-90分", "70-80分", "60-70分", "60分以下"],
  yAxisData: [
    {
      value: 60,
      label: "结构化",
      itemStyle: {
        color: "#EE752F",
      },
    },
    {
      value: 100,
      label: "文本",
      itemStyle: {
        color: "#F2BD42",
      },
    },
    {
      value: 30,
      label: "音频",
      itemStyle: {
        color: "#58A55C",
      },
    },
    {
      value: 10,
      label: "视频",
      itemStyle: {
        color: "#5087EC",
      },
    },
    {
      value: 50,
      label: "图片",
      itemStyle: {
        color: "#409eff",
      },
    },
  ],
};
const scoreUl = ref([
  {
    label:'未评分',
    value:0
  },
  {
    label:'已评分',
    value:1
  },
]);
/**
 * 获取数据集列表
 */
const datasets = ref([]);
const pageNum = ref(1);
const pageSize = ref(10);
const total = ref(0);
const getDatasetsList = () => {
  const params = {
    "isScored": activeIndex.value ? true : false,
    "name": "",
    "pageNum": pageNum.value,
    "pageSize": pageSize.value
  };
  datasetsList(params).then((res:any) => {
    res.records = res.records.map(item => {
      return {
        ...item,
        createTime:moment(item.createTime).format('YYYY-MM-DD HH:mm:ss')
      }
    })
    datasets.value = res.records;
    total.value = 7;
  })
}
bus.on('datasets', () => {
  getDatasetsList();
});

const handleSizeChange = (val: number) => {
}
const handleCurrentChange = (val: number) => {
  pageNum.value = val;
  getDatasetsList();
}
getDatasetsList();

const handleScoreItem = (index) => {
  activeIndex.value = index;
  getDatasetsList();
}
const router = useRouter();
const handleScoreListitem = (row) => {
  switch(activeIndex.value) {
    case 0:
      router.push({
        path:'/score/nScore',
        query:{
          id:row.id
        }
      });
      break;
    case 1:
      router.push('/score/yScore');
      break;
  }
};
const isVisible = ref(false);
const handleUploadData = () => {
  isVisible.value = true;
}
</script>

<style scoped lang="scss">
.scoreStatistics {
  padding: 0 20px;
  padding-bottom: 80px;

  .overview {
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 1);
    color: rgba(16, 16, 16, 1);
    font-size: 14px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
    font-family: Roboto;
    margin-top: 10px;
    border-radius: 8px;
    padding: 20px;
    display: flex;

    .dataSetNumber {
      li {
        width: 260px;
        height: 120px;
        background: url("@/assets/score1.png") no-repeat;
        display: flex;

        img {
          width: 61px;
          height: 61px;
          margin: 28px 23px 0 20px;
        }

        .score {
          span {
            font-family: Roboto;
            display: block;
          }

          .label {
            color: #fff;
            margin-top: 20px;
            font-size: 18px;
          }

          .value {
            color: #fff;
            margin-top: 10px;
            font-size: 30px;
          }
        }
      }

      li:last-child {
        background: url("@/assets/score2.png") no-repeat;
        margin-top: 30px;
      }
    }

    .yAxisDataUl {
      width: 77px;
      margin: 100px 30px 0 -100px;

      li {
        margin-bottom: 5px;
        text-align: right;

        .yColor {
          display: inline-block;
          width: 24px;
          height: 12px;
          border-radius: 4px;
          margin-left: 5px;
        }
      }
    }
  }

  .scoreAndUpload {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;

    .scoreUl {
      display: flex;

      li {
        font-family: PingFangSC, PingFang SC;
        font-size: 18px;
        color: #999;
        line-height: 33px;
        letter-spacing: 3px;
        text-align: left;
        font-style: normal;
        position: relative;
        cursor: pointer;
      }

      li:last-child {
        margin-left: 10px;
        text-indent: 10px;
      }

      li:last-child::before {
        content: "";
        height: 60%;
        display: inline-block;
        border: 1px solid #999;
        background: #999;
        position: absolute;
        top: 6px;
        left: 0px;
      }

      .active {
        color: #000;
        font-weight: 550;
      }
    }

    .uploadData {
      width: 120px;
      height: 32px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #0091ff;
      font-family: PingFangSC, PingFang SC;
      font-size: 14px;
      color: #0091ff;
      line-height: 25px;
      letter-spacing: 2px;
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .uploadData:hover {
      background-color: #f5f5f5;
    }
  }

  .scoreList {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;

    .scoreListItem {
      cursor: pointer;
      width: 32%;
      background: #ffffff;
      box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.25);
      border-radius: 8px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 14px 17px;

      .label {
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: rgba(0, 0, 0, 0.74);
        line-height: 25px;
        text-align: left;
        font-style: normal;
      }

      .value {
        height: 77px;
        font-family: STHeitiSC, STHeitiSC;
        font-weight: 300;
        font-size: 14px;
        color: rgba(0, 0, 0, 0.68);
        line-height: 25px;
        font-style: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
        margin-top: 5px;
      }

      .lookList {
        color: rgba(0, 0, 0, 0.38);
        margin-top: 10px;
        display: flex;

        span {
          padding: 0 10px;
          border-right: 2px solid rgba(0, 0, 0, 0.28);
          display: flex;
          align-items: center;
          font-size: 15px;

          .elIcon {
            margin-right: 10px;
          }
        }

        span:last-child {
          border: 0;
        }

        span:first-child {
          padding-left: 0;
        }
      }
    }
  }

  .pagination {
    display: flex;
    justify-content: flex-end;

    ::v-deep .el-pagination {
      background: #f6f6f6 !important;

      .el-pager li,
      button {
        background: #f6f6f6 !important;
      }
    }
  }
}
</style>
